package com.yx.elastic.elasticcm.base;

/**
 * Created by chenzp on 18-8-1.
 */
public enum ISearchExceptionCode {

    NOT_ANNO("未声明注解",2401),
    NOT_TYPE("文档类型不能为空",2402),
    NOT_INDEX("节点不能为空",2403),
    ID_TYPE_ERROR("文档ID类型不正确",2404),
    CONNECT_ERROR("连接异常",2405),
    UNKNOWN_ERROR("未知异常",2406),
    OTHER_ERROR("其他异常",2407);

    private String message;

    private int code;

    ISearchExceptionCode(String message, int code) {
        this.message = message;
        this.code = code;
    }

    /**
     * 根据状态code获取枚举
     * @return
     */
    public static ISearchExceptionCode getByCode(int code) {
        for (ISearchExceptionCode status : ISearchExceptionCode.values()) {
            if (status.getCode()== code) {
                return status;
            }
        }
        return null;
    }

    /**
     * 根据状态code获取枚举值
     * @return
     */
    public static String getNameByCode(int code) {
        for (ISearchExceptionCode status : ISearchExceptionCode.values()) {
            if (status.getCode() == code) {
                return status.message;
            }
        }
        return null;
    }

    public String getMessage() {
        return message;
    }

    public int getCode() {
        return code;
    }
}
